import { View } from "../../../mvc/core/View";
import { PageTool } from "../../../common/global/PageTool";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { ResFileConst } from "../../resource/ResFileConst";
import { TilePanel } from "../equipment/TilePanel";
import { KingBigGiftItemRenderer } from "./KingBigGiftItemRenderer";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ListEvent } from "../../../../fl/events/ListEvent";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { KingRewardItemRenderer } from "./KingRewardItemRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { ArenaRewardConfig } from "../../resource/ArenaRewardConfig";
import { KingwarNoteType } from "./KingwarNoteType";
import { ClockManager } from "../../manager/ClockManager";
import { GiftBagConfig } from "../../resource/GiftBagConfig";
type int = number;
//class KingWarInfoPanel
    
    export  class KingWarInfoPanel extends View
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 10);
            this._displayListArr = [];
            this._curArr = [];
            this._career = Cache.instance.role.entityInfo.career;
            this.initView();
            return;
        }

        /* internal  */setFirClick(): void
        {
            this._bigGiftTList.selectedIndex = 0;
            this.updateRewardList(this._bigGiftTList.selectedItem.data as int);
            return;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(0, 0, 802, 325, this);
            ObjCreate.createBg(267, 34, 400, 3, this, ImagesConst.Line).rotation = 90;
            ObjCreate.createBg(537, 34, 400, 3, this, ImagesConst.Line).rotation = 90;
            this._sbmManIIHead = ObjCreate.createBitmap("", 2, 2, this);
            this._sbmManIHead = ObjCreate.createBitmap("", 266, 2, this);
            this._sbmManIIIHead = ObjCreate.createBitmap("", 543, 2, this);
            this._sbmManIIBody = ObjCreate.createBitmap("", 48, 96, this);
            this._sbmManIBody = ObjCreate.createBitmap("", 323, 96, this);
            this._sbmManIIIBody = ObjCreate.createBitmap("", 589, 96, this);
            this._sbmBlackQueIIA = ObjCreate.createBitmap("", 59, 209, this);
            this._sbmBlackQueIIB = ObjCreate.createBitmap("", 160, 209, this);
            this._sbmBlackQueIIIA = ObjCreate.createBitmap("", 602, 209, this);
            this._sbmBlackQueIIIB = ObjCreate.createBitmap("", 706, 209, this);
            this._sbmBrightQueIA = ObjCreate.createBitmap("", 336, 209, this);
            this._sbmBrightQueIB = ObjCreate.createBitmap("", 440, 209, this);
            var loc1=ObjCreate.createBg(95, 200, 65, 65, this, ImagesConst.PackItemBg);
            var loc2=ObjCreate.createBg(370, 200, 65, 65, this, ImagesConst.PackItemBg);
            var loc3=ObjCreate.createBg(638, 200, 65, 65, this, ImagesConst.PackItemBg);
            var loc4=new BaseItem();
            var loc5=new BaseItem();
            var loc6=new BaseItem();
            loc4.move(97, 202);
            loc5.move(372, 202);
            loc6.move(640, 202);
            loc4.setSize(60, 60);
            loc5.setSize(60, 60);
            loc6.setSize(60, 60);
            loc4.isDragAble = false;
            loc5.isDragAble = false;
            loc6.isDragAble = false;
            loc4.isDropAble = false;
            loc5.isDropAble = false;
            loc6.isDropAble = false;
            addChild(loc4);
            addChild(loc5);
            addChild(loc6);
            loc4.itemData = new ItemData(14011550);
            loc5.itemData = new ItemData(14011551);
            loc6.itemData = new ItemData(14011552);
            loc4.isShowToolTip = false;
            loc5.isShowToolTip = false;
            loc6.isShowToolTip = false;
            var loc7=ObjCreate.createGTextField("", 97, 202, 60, 60, this);
            var loc8=ObjCreate.createGTextField("", 372, 202, 60, 60, this);
            var loc9=ObjCreate.createGTextField("", 640, 202, 60, 60, this);
            loc7.toolTipData = HTMLUtil.addColor(Language.getString(70437), "#ffffff");
            loc8.toolTipData = HTMLUtil.addColor(Language.getString(70438), "#ffffff");
            loc9.toolTipData = HTMLUtil.addColor(Language.getString(70439), "#ffffff");
            this._sbmTitleII = ObjCreate.createBitmap("", 82, 267, this);
            this._sbmTitleI = ObjCreate.createBitmap("", 360, 267, this);
            this._sbmTitleIII = ObjCreate.createBitmap("", 626, 267, this);
            this._sbmTitleSameII = ObjCreate.createBitmap("", 65, 291, this);
            this._sbmTitleSameI = ObjCreate.createBitmap("", 344, 291, this);
            this._sbmTitleSameIII = ObjCreate.createBitmap("", 615, 291, this);
            ObjCreate.createBg(0, 328, 802, 157, this);
            ObjCreate.createBg(4, 333, 147, 147, this);
            this.tileBm = ObjCreate.createBg(5, 336, 130, 20, this, ImagesConst.TileBg);
            this._sbmRewardShow = ObjCreate.createBitmap("", 35, 337, this);
            this._rightRange = new Object /* flash.display.Sprite */();
            this._rightRange.x = 150;
            this._rightRange.y = 352;
            this._rightRange.graphics.beginFill(16777215, 0);
            this._rightRange.graphics.drawEllipse(0, 0, 24, 68);
            this._rightRange.graphics.endFill();
            addChild(this._rightRange);
            this._leftRange = new Object /* flash.display.Sprite */();
            this._leftRange.x = 773;
            this._leftRange.y = 352;
            this._leftRange.graphics.beginFill(16777215, 0);
            this._leftRange.graphics.drawEllipse(0, 0, 24, 68);
            this._leftRange.graphics.endFill();
            addChild(this._leftRange);
            var loc10;
            this._rightRange.useHandCursor = loc10 = true;
            this._rightRange.buttonMode = loc10;
            this._leftRange.useHandCursor = loc10 = true;
            this._leftRange.buttonMode = loc10;
            this._rightRange.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._leftRange.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._btnLeft = ObjCreate.createGLoadedButton(ResFileConst.KingLeftTurnBtn, 152, 372, 20, 20, this);
            this._btnRight = ObjCreate.createGLoadedButton(ResFileConst.KingRightTurnBtn, 775, 372, 20, 20, this);
            this._btnLeft.visible = loc10 = false;
            this._btnRight.visible = loc10;
            this._btnRight.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._btnLeft.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._btnAud = ObjCreate.createGLoadedButton(ResFileConst.KingCrownBtn, 19, 363, 117, 34, this);
            this._btnAud.drawNow();
            this._btnGroup = ObjCreate.createGLoadedButton(ResFileConst.KingCrownBtn, 19, 398, 117, 34, this);
            this._btnGroup.drawNow();
            this._btnFinal = ObjCreate.createGLoadedButton(ResFileConst.KingCrownBtn, 19, 433, 117, 34, this);
            this._btnFinal.drawNow();
            this._txAudBtn = ObjCreate.createTextField(Language.getString(70411), 62, 377, 60, 20, this);
            this._txGroupBtn = ObjCreate.createTextField(Language.getString(70412), 59, 412, 66, 20, this);
            this._txFinalBtn = ObjCreate.createTextField(Language.getString(70413), 59, 447, 66, 20, this);
            this._txFinalBtn.mouseEnabled = loc10 = false;
            this._txGroupBtn.mouseEnabled = loc10 = loc10;
            this._txAudBtn.mouseEnabled = loc10;
            this._btnAud.addEventListener(flash.events.MouseEvent.CLICK, this.onRewardBtnClick);
            this._btnGroup.addEventListener(flash.events.MouseEvent.CLICK, this.onRewardBtnClick);
            this._btnFinal.addEventListener(flash.events.MouseEvent.CLICK, this.onRewardBtnClick);
            this._bigGiftTList = new TilePanel();
            this._bigGiftTList.columnWidth = 96;
            this._bigGiftTList.rowHeight = 100;
            this._bigGiftTList.columnCount = 6;
            this._bigGiftTList.rowCount = 1;
            this._bigGiftTList.horizontalGap = 4;
            this._bigGiftTList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._bigGiftTList.setStyle("cellRenderer", KingBigGiftItemRenderer);
            this._bigGiftTList.setSize(610, 105);
            this._bigGiftTList.move(174, 332);
            this._bigGiftTList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._bigGiftTList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._bigGiftTList.addEventListener(ListEvent.ITEM_CLICK, this.onBigGiftItemClick);
            addChild(this._bigGiftTList);
            ObjCreate.createBg(200, 436, 500, 45, this, ImagesConst.RemainningTimeBg);
            this._rewardTList = new GTileList();
            this._rewardTList.columnWidth = 38;
            this._rewardTList.rowHeight = 38;
            this._rewardTList.columnCount = 10;
            this._rewardTList.rowCount = 1;
            this._rewardTList.horizontalGap = 5;
            this._rewardTList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._rewardTList.setStyle("cellRenderer", KingRewardItemRenderer);
            this._rewardTList.setSize(430, 40);
            this._rewardTList.move(237, 440);
            this._rewardTList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._rewardTList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._rewardTList);
            this._pagebar = new PageSelecter();
            this._pagebar.mode = PageSelecter.SingleMode;
            this._pagebar.move(709, 455);
            this._pagebar.maxPage = 2;
            this._pagebar.currentPage = 1;
            this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            addChild(this._pagebar);
            LoaderHelp.addResCallBack(ResFileConst.kingWar, this.onLoadBmResource);
            this.rewardBtnClick(this._btnAud);
            return;
        }

        protected onBigGiftItemClick(arg1: ListEvent): void
        {
            var loc1=arg1.item.data as int;
            this.updateRewardList(loc1);
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._sbmManIHead.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigTitle1);
            this._sbmManIIHead.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigTitle2);
            this._sbmManIIIHead.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigTitle3);
            this._sbmManIBody.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_man1);
            this._sbmManIIBody.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_man2);
            this._sbmManIIIBody.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_man3);
            this._sbmBlackQueIIA.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_blackQue);
            this._sbmBlackQueIIB.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_blackQue);
            this._sbmBlackQueIIIA.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_blackQue);
            this._sbmBlackQueIIIB.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_blackQue);
            this._sbmBrightQueIA.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_brightQue);
            this._sbmBrightQueIB.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_brightQue);
            this._sbmTitleI.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_Title1);
            this._sbmTitleII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_Title2);
            this._sbmTitleIII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_Title3);
            this._sbmTitleSameI.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigPack);
            this._sbmTitleSameII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigPack);
            this._sbmTitleSameIII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_bigPack);
            this._sbmRewardShow.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_rewardShow);
            return;
        }

        protected onRLBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._btnRight: case this._rightRange:
                {
                    this.btnRightClick();
                    break;
                }
                case this._btnLeft: case this._leftRange:
                {
                    this.btnLeftClick();
                    break;
                }
            }
            return;
        }

        /* internal  */btnRightClick(): void
        {
            if (this._startIndex + KingWarInfoPanel.MAX_DISPLAY_LENGTH < this._curArr.length) 
            {
                var loc1;
                var loc2=((loc1 = this)._startIndex + 1);
                loc1._startIndex = loc2;
                this._displayListArr = this.getCurrentDisplayList();
                this._bigGiftTList.dataProvider = new DataProvider(this._displayListArr);
                this.updateRewardList(this._bigGiftTList.selectedItem.data as int);
            }
            return;
        }

        /* internal  */btnLeftClick(): void
        {
            if (this._startIndex > 0) 
            {
                var loc1;
                var loc2=((loc1 = this)._startIndex - 1);
                loc1._startIndex = loc2;
                this._displayListArr = this.getCurrentDisplayList();
                this._bigGiftTList.dataProvider = new DataProvider(this._displayListArr);
                this.updateRewardList(this._bigGiftTList.selectedItem.data as int);
            }
            return;
        }

        /* internal  */getCurrentDisplayList(): Array<any>
        {
            var loc1=[];
            var loc2=this._startIndex + KingWarInfoPanel.MAX_DISPLAY_LENGTH;
            var loc3=this._startIndex;
            while (loc3 < loc2) 
            {
                loc1.push(this._curArr[loc3]);
                ++loc3;
            }
            return loc1;
        }

        /* internal  */showRLBtn(arg1: int): void
        {
            if (arg1 > 6) 
            {
                var loc1;
                this._btnLeft.visible = loc1 = true;
                this._btnRight.visible = loc1;
            }
            else 
            {
                this._btnLeft.visible = loc1 = false;
                this._btnRight.visible = loc1;
            }
            return;
        }

        protected onRewardBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.rewardBtnClick(arg1.target as GLoadedButton);
            return;
        }

        /* internal  */rewardBtnClick(arg1: GLoadedButton): void
        {
            this._curArr = [];
            var loc1=arg1;
            switch (loc1) 
            {
                case this._btnAud:
                {
                    this._flagFinal = false;
                    this._curArr = ArenaRewardConfig.instance.getBigPackArr(KingwarNoteType.AUDITIONS);
                    this.showRLBtn(this._curArr.length);
                    this.changeBigGiftList(this._curArr);
                    this.setFirClick();
                    break;
                }
                case this._btnGroup:
                {
                    this._flagFinal = false;
                    this._curArr = ArenaRewardConfig.instance.getBigPackArr(KingwarNoteType.GROUPGAME);
                    this.showRLBtn(this._curArr.length);
                    this.changeBigGiftList(this._curArr);
                    this.setFirClick();
                    break;
                }
                case this._btnFinal:
                {
                    this._flagFinal = true;
                    this._curArr = ArenaRewardConfig.instance.getBigPackArr(KingwarNoteType.FINALGAME);
                    this.showRLBtn(this._curArr.length);
                    this.changeBigGiftList(this._curArr);
                    this.setFirClick();
                    break;
                }
            }
            return;
        }

        /* internal  */changeBigGiftList(arg1: Array<any>): void
        {
            var loc2=0;
            var loc1=arg1.length;
            if (loc1 < KingWarInfoPanel.MAX_DISPLAY_LENGTH && loc1 >= 1) 
            {
                loc2 = (this._bigGiftTList.width - (this._bigGiftTList.columnWidth * loc1 + (loc1 - 1) * this._bigGiftTList.horizontalGap)) * 0.5 + 174;
                this._bigGiftTList.move(loc2, 333);
                this._bigGiftTList.dataProvider = new DataProvider(arg1);
            }
            else if (loc1 >= KingWarInfoPanel.MAX_DISPLAY_LENGTH) 
            {
                this._bigGiftTList.move(174, 333);
                this._bigGiftTList.dataProvider = new DataProvider([arg1[0], arg1[1], arg1[2], arg1[3], arg1[4], arg1[5]]);
            }
            return;
        }

        protected onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageTool.getByPageNo(this._pagebar.currentPage);
            this._rewardTList.dataProvider = new DataProvider(loc1);
            return;
        }

        public updateInfo(): void
        {
            var loc1=ClockManager.instance.nowDate.getTime();
            if (!Cache.instance.kingwar.sArenaInfo) 
            {
            };
            return;
        }

        protected onSignTxClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        /* internal  */updateRewardList(arg1: int): void
        {
            var loc1=null;
            var loc2=false;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            if (this._flagFinal) 
            {
                loc1 = ArenaRewardConfig.instance.getBigPackArr(KingwarNoteType.FINALGAME);
                loc3 = 0;
                while (loc3 < loc1.length) 
                {
                    if (arg1 == loc1[0] || arg1 == loc1[1] || arg1 == loc1[2]) 
                    {
                        loc2 = true;
                        break;
                    }
                    ++loc3;
                }
                if (loc2) 
                {
                    this._pagebar.currentPage = 1;
                    loc4 = GiftBagConfig.instance.getInfoByType(arg1);
                    loc5 = [];
                    loc6 = [];
                    loc7 = 0;
                    while (loc7 < loc4.length) 
                    {
                        loc5.push(0);
                        ++loc7;
                    }
                    this._pageTool.array = loc5;
                    this._pagebar.maxPage = Math.ceil(loc5.length / 10);
                    loc6 = this._pageTool.getByPageNo(1);
                    this._rewardTList.dataProvider = new DataProvider(loc6);
                }
                else 
                {
                    this.normalShowRewardList(arg1);
                }
            }
            else 
            {
                this.normalShowRewardList(arg1);
            }
            return;
        }

        /* internal  */normalShowRewardList(arg1: int): void
        {
            var loc2=null;
            this._pagebar.currentPage = 1;
            var loc1=GiftBagConfig.instance.getInfoByType(arg1);
            var loc3=[];
            var loc4=[];
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                if (loc2.type != 3) 
                {
                    continue;
                }
                loc3.push(loc2);
            }
            this._pageTool.array = loc3;
            this._pagebar.maxPage = Math.ceil(loc3.length / 10);
            loc4 = this._pageTool.getByPageNo(1);
            this._rewardTList.dataProvider = new DataProvider(loc4);
            return;
        }

        /* internal */ static /* const */MAX_DISPLAY_LENGTH: int=6;

        /* internal */ /* var */_leftRange: Object /* flash.display.Sprite */;

        /* internal */ /* var */_sbmManIHead: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmManIIHead: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmManIIIHead: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmManIBody: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmManIIBody: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmManIIIBody: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmBlackQueIIA: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmBlackQueIIB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmBlackQueIIIA: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_displayListArr: Array<any>;

        /* internal */ /* var */_sbmBrightQueIA: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmBrightQueIB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleI: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleIII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleSameI: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleSameII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmTitleSameIII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmRewardShow: Object /* flash.display.Bitmap */;

        /* internal */ /* var */tileBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rewardTList: GTileList;

        /* internal */ /* var */_bigGiftTList: TilePanel;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_career: int;

        /* internal */ /* var */_startIndex: int=0;

        /* internal */ /* var */_flagFinal: Boolean;

        /* internal */ /* var */_curArr: Array<any>;

        /* internal */ /* var */_btnAud: GLoadedButton;

        /* internal */ /* var */_btnGroup: GLoadedButton;

        /* internal */ /* var */_sbmBlackQueIIIB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnFinal: GLoadedButton;

        /* internal */ /* var */_txAudBtn: Object /* flash.text.TextField */;

        /* internal */ /* var */_txGroupBtn: Object /* flash.text.TextField */;

        /* internal */ /* var */_txFinalBtn: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnRight: GLoadedButton;

        /* internal */ /* var */_btnLeft: GLoadedButton;

        /* internal */ /* var */_rightRange: Object /* flash.display.Sprite */;
    }
